﻿using System.Web.Mvc;
using System.Web.Routing;
using System.Text;
using System.Web.UI.WebControls;
using System.Collections.Generic;
using System.Collections.Specialized;
using MVC.Web.UI.Attributes;
using System;

namespace MVC.Web.UI.Dialog
{
    public  class WebDialog : MvcControl
    {
        #region Fields    
        private string _dialogId = "Dialog1";
        private string _content = string.Empty;
         
        #region Old code
        private bool _autoOpen = true;
        //private object[] buttons = { };
        //private bool _closeOnEscape = true;
        //private string _closeText = "'close'";
        //private string _dialogClass = "''";
        //private bool _draggable = true;
        //private string _hide = "null";
        //private string _height = "'auto'";
        //private string _maxHeight = "false";
        //private string _maxWidth = "false";
        //private int _minHeight = 150;
        //private bool _modal = false;
        //private string _position = "'center'";
        //private bool _resizable = true;
        //private string _show = "null";
        //private bool _stack = true;
        //private int _width = 300;
        //private int _zIndex = 1000;
        //private int _minWidth = 150; 
        #endregion

        private DialogType _type = DialogType.Default;
        private Dictionary<DialogEvents, string> _mapHandler = null;
        private string _trigger = string.Empty;


        #endregion

        #region Constructors

        public WebDialog(HtmlHelper htmlHelper)
            :base("div",htmlHelper.ViewContext)
        {
        }

        #endregion

        #region Properties
        internal string Scripts { get; set; }

        public HtmlHelper _htmlHelper { get; set; }

        public string Trigger { get; set; }
        
        public Dictionary<DialogEvents, string> MapHandlers
        {
            get 
            {
                if (this._mapHandler == null)
                    return this._mapHandler = new Dictionary<DialogEvents, string>(10);
                return this._mapHandler;
            }   
        }

        internal string ModalMassage { get{ return "Cancel: function() {$(this).dialog('close');}";} }
       
        internal string ModalConfirmation { get { return "'Delete all items': function() {$(this).dialog('close');},Cancel: function() { $(this).dialog('close');}"; } }

        public DialogType Type { get; set; }
      
        public Action Content { get; set; }

        public string Name { get; set; }

        public bool AutoOpen 
        {
            get 
            {
                return this._autoOpen; 
            }
            set 
            {
                this._autoOpen = value;
            } 
        }
       
        public bool CloseOnEscape { get; set; }
       
        public string CloseText { get; set; }
       
        public string Class { get; set; }
       
        public bool Draggable { get; set; }
       
        public string Height { get; set; }

        public string MaxHeight { get; set; }

        public string MaxWidth { get; set; }

        public int MinHeight { get; set; }
       
        public int MinWidth { get; set; }

        public bool Modal { get; set; }
       
        public bool Resizable { get; set; }
        
        public bool Stack { get; set; }
         
        public string Title { get; set; }
        
        public int Width { get; set; }
           
        public int ZIndex { get; set; }

        #endregion

        #region Overrides

        protected override void RenderContents(System.Web.UI.HtmlTextWriter writer)
        {
            this.Content.Invoke();
        }

        protected override void RenderScripts(System.Web.UI.HtmlTextWriter writer)
        {    
            writer.Write(this.Scripts);
        }

        #endregion

        #region Utill
       
      

        #endregion

        
    }

} 
    
